<template>
  <div
    class="singer"
    v-loading="!singers.length"
  >
    <index-list
      :data="singers"
      @select="selectSinger"
    ></index-list>
    <router-view v-slot="{Component}">
      <transition
        appear
        name="slide"
      >
        <component
          :is="Component"
          :data="slectedSinger"
        />
      </transition>
    </router-view>
  </div>
</template>

<script>
import { getSingerList } from "@/service/singer";
import IndexList from "@/components/base/index-list/index-list.vue";
import storage from "good-storage";
import { SINGER_KEY } from "@/assets/js/constant";
export default {
  name: "singerView",
  components: {
    IndexList,
  },
  data() {
    return {
      singers: [],
      slectedSinger: null,
    };
  },
  methods: {
    selectSinger(singer) {
      this.cacheSinger(singer);
      this.slectedSinger = singer;
      this.$router.push({
        path: `/singer/${singer.mid}`,
      });
    },
    cacheSinger(singer) {
      storage.session.set(SINGER_KEY, singer);
    },
  },
  async created() {
    const res = await getSingerList();
    this.singers = res.singers;
  },
};
</script>

<style lang="scss" scoped>
.singer {
  position: fixed;
  width: 100%;
  top: 88px;
  bottom: 0;
}
</style>